#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File        :   20. 有效的括号.py    
@Contact     :   lhouctcs@163.com
@License     :   MIT
@Time        :   2023/2/12 20:27
@Author      :   lhou 
@Version     :   0.1.0
@Description :
"""


# import lib
class Solution:
    def isValid(self, s: str) -> bool:
        l = []
        d = {
            "(": ")",
            "[": "]",
            "{": "}"
        }
        for i in s:
            if i in d.keys():
                l.append(d[i])
            else:
                if not l: return False
                if i == l[-1]:
                    l.pop(-1)
                else:
                    return False
        return len(l) == 0
